package com.webflux.service.impl;

import com.webflux.entity.TbCity;
import com.webflux.mapper.TbCityRepository;
import com.webflux.service.TbCityService;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Service
public class TbCityServiceImpl implements TbCityService {

    @Resource
    private TbCityRepository cityRepository;

    @Override
    public Mono<TbCity> add(TbCity city) {
        city.setCreateAt(LocalDateTime.now());
        return cityRepository.save(city);
    }

    @Override
    public Mono<TbCity> edit(TbCity city) {
        return cityRepository.save(city);
    }

    @Override
    public Mono<Void> delete(TbCity city) {
        return cityRepository.delete(city);
    }

    @Override
    public Flux<TbCity> search(String cityName) {
        return cityRepository.findByNameLike(cityName);
    }

}
